package com.zyx.javademo.collection.collections;

import org.apache.commons.collections4.queue.CircularFifoQueue;

/**
 * @author Yaxi.Zhang
 * @since 2021/10/8 18:32
 * desc: commons-collections4库CircularFifoQueue案例
 */
public class CircularFifoQueueDemo {
    public static void main(String[] args) {
        // 创建大小为3的 先进先出 循环队列, 默认值长度为32
        CircularFifoQueue<Integer> cfq = new CircularFifoQueue<>(3);
        // If the queue is full, the least recently added, element is discarded so that a new element can be inserted.
        cfq.add(1);
        cfq.add(2);
        cfq.add(3);
        // offer与add等价
        cfq.offer(4);

        System.out.println(cfq);
        System.out.println(cfq.size());

        // 查看首个元素, 不删除
        System.out.println(cfq.peek());
        System.out.println(cfq);

        // 查看并删除(取出)首个元素
        System.out.println(cfq.poll());
        System.out.println(cfq);
        System.out.println(cfq.size());




    }
}
